#include<vector>
using namespace std;
class Solution {
public:
    vector<int> findClosedNumbers(int num) {
        vector<int>res = { -1,-1 };
        int prev = num & 1;
        int cnt = prev == 1;
        int mask = 1;
        for (int i = 1; i < 32; ++i) {
            mask += 1 << i;
            int cur = (num >> i) & 1;
            if (prev == 1 && cur == 0) {
                int first = (num & (~mask)) + (1 << i);
                for (int j = 0; j < cnt-1; ++j)
                    first += 1 << j;
                res[0] = first;
            }
            if (prev == 0 && cur == 1) {
                int second = num & (~mask);
                for (int j = i - 1; j >= i - cnt - 1; --j)
                    second += 1 << j;
                res[1] = second;
            }
            prev = cur;
            cnt += cur == 1;
            if (res[0] != -1 && res[1] != -1)
                break;
        }
        return res;
    }
};

int main() {
    Solution sol;
    sol.findClosedNumbers(2);
}